#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/EC2'
require 'basic_configuration'
require 'aws_context'
require 'pp'

# Register the given image.
if ARGV[0] == '-?' || ARGV.size != 1 then
  puts "usage: register-image image-name"
  exit 1
end
name = ARGV[0]

Signal.trap("INT") do
  exit 2
end

config = BasicConfiguration.new
ec2 = AwsContext.instance.ec2(*config.keys)
begin
  #puts "registering #{name}"
  res = ec2.register_image(name)
rescue
  puts "error #{$!} #{name}"
  exit 1
end

